package IOStream.IOStreamDome;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * ClassName:IOStream005
 * Package:IOStream.IOStreamDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/28-21:34
 * @Version:v1.0
 */
public class IOStream005 {
    /*JDK9:IO流捕获异常的写法*/
    public static void main(String[] args) throws FileNotFoundException {
        //创建对象
        FileInputStream fis = new FileInputStream("E:\\aaa\\a.txt");//读
        FileOutputStream fos = new FileOutputStream("E:\\aaa\\bbb\\copy.txt");//写
        try (fis; fos) {
            //拷贝
            //核心：边读边写
            int b;
            while ((b = fis.read()) != -1) {
                fos.write(b);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

//        //释放资源
//        //规则:先开的流最后关闭
//        fos.close();
//        fis.close();
    }
}
